package com.kjlSign;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.security.MessageDigest;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author: hfxiang
 * @Description:
 * @date: 2022/11/8 10:13
 */
public class Main {
    static String allOmsEmail = "20143@hxr.com\n" +
            "ceshi1@hxr.com\n" +
            "23038@hxr.com\n" +
            "11074@hxr.com\n" +
            "07018@hxr.com\n" +
            "21076@hxr.com\n" +
            "libingbing@hxr.com\n" +
            "chenyufeng@hxr.com\n" +
            "18126@hxr.com\n" +
            "01611@hxr.com\n" +
            "qianjiaqin@hxr.com\n" +
            "02097@hxr.com\n" +
            "11026@hxr.com\n" +
            "24037@hxr.com\n" +
            "wuwenjuan@hxr.com\n" +
            "huangzihao@hxr.com\n" +
            "ceshi2@hxr.com\n" +
            "20020@hxr.com\n" +
            "10150@hxr.com\n" +
            "zhulongjia@hxr.com\n" +
            "21003@hxr.com\n" +
            "18001@hxr.com\n" +
            "16042@hxr.com\n" +
            "19107@hxr.com\n" +
            "10001@hxr4.com\n" +
            "yinlina@hxr.com\n" +
            "wangdongjie@hxr.com\n" +
            "22044@hxr.com\n" +
            "21163@hxr.com\n" +
            "10051@hxr.com\n" +
            "xujiafei@hxr.com\n" +
            "09001@hxr.com\n" +
            "10019@hxr.com\n" +
            "01149@hxr.com\n" +
            "20021@hxr.com\n" +
            "07037@hxr.com\n" +
            "yinchenxiao@hxr.com\n" +
            "20062@hxr.com\n" +
            "02048@hxr.com\n" +
            "wangyan@hxr.com\n" +
            "24072@hxr.com\n" +
            "21675@hxr.com\n" +
            "01182@hxr.com\n" +
            "yanshichao@hxr.com\n" +
            "22089@hxr.com\n" +
            "04043@hxr.com\n" +
            "sangqiuyang@hxr.com\n" +
            "liushuai@hxr.com\n" +
            "14087@hxr.com\n" +
            "25040@hxr.com\n" +
            "peixun2@hxr.com\n" +
            "24076@hxr.com\n" +
            "01018@hxr.com\n" +
            "zhangwanwan@hxr.com\n" +
            "01012@hxr.com\n" +
            "19077@hxr.com\n" +
            "020002@hxr.com\n" +
            "14092@hxr1.com\n" +
            "24099@hxr.com\n" +
            "20144@hxr.com\n" +
            "taoguansheng@hxr.com\n" +
            "01171@hxr.com\n" +
            "21025@hxr.com\n" +
            "01611@hxr1.com\n" +
            "24002@hxr.com\n" +
            "17008@hxr.com\n" +
            "22046@hxr.com\n" +
            "17001@hxr1.com\n" +
            "20020@hxr4.com\n" +
            "zhucongde@hxr.com\n" +
            "10156@hxr.com\n" +
            "01165@hxr.com\n" +
            "10135@hxr.com\n" +
            "91744@hxr.com\n" +
            "02056@hxr.com\n" +
            "01053@hxr.com\n" +
            "10001@hxr3.com\n" +
            "21145@hxr.com\n" +
            "11093@hxr.com\n" +
            "xiaxuan@hxr.com\n" +
            "zhangjiani@hxr.com\n" +
            "12089@hxr.com\n" +
            "21146@hxr.com\n" +
            "17006@hxr.com\n" +
            "07012@hxr.com\n" +
            "20136@hxr.com\n" +
            "11112@hxr.com\n" +
            "10047@hxr.com\n" +
            "19084@hxr.com\n" +
            "20004@hxr.com\n" +
            "10004@hxr.com\n" +
            "01026@hxr.com\n" +
            "09008@hxr.com\n" +
            "11015@hxr.com\n" +
            "10001@hxr2.com\n" +
            "01079@hxr.com\n" +
            "linlu@hxr.com\n" +
            "01075@hxr.com\n" +
            "wanglei@hxr.com\n" +
            "02127@hxr.com\n" +
            "14096@hxr.com\n" +
            "20007@hxr.com\n" +
            "01118@hxr.com\n" +
            "10634@hxr.com\n" +
            "25054@hxr.com\n" +
            "19112@hxr.com\n" +
            "05005@hxr.com\n" +
            "20020@hxr2.com\n" +
            "22058@hxr.com\n" +
            "gongyoutao@hxr.com\n" +
            "10167@hxr.com\n" +
            "20172@hxr.com\n" +
            "10110@hxr.com";

    public static void main(String[] arg) throws Exception {

        System.out.println(getEmailError());
    }

    public static String getEmailError() throws Exception {
        String[] allOmsEmailA = allOmsEmail.split("\n");
        List<String> allOmsEmailList = Arrays.asList(allOmsEmailA);
        List<String> kjlEmailList = transferJsonToEmailList();
        List<String> resList = new ArrayList();
        Map<String,Integer> omsEmailMap = new HashMap();
        for (String email : allOmsEmailList) {
            omsEmailMap.put(email,1);
        }
        for (String kjlEmail : kjlEmailList) {
            Integer isExits = omsEmailMap.get(kjlEmail);
            if (isExits==null){
                resList.add(kjlEmail);
            }
        }
        return resList.toString();
    }

    //获取sign并拼接为查询参数
    public static String getUrlParamStr() {
        String appuid = "ebd382fa2a544038b468a088292f5a61";//ceshi2@hxr.com
        String appKeyT = "fIiRuduT28";
        String appSecretT = "G3U0WzXR92jrtpLhFGY9l8D19OBilPkc";
        long timestamp = System.currentTimeMillis();
        String sign  = md5(appSecretT + appKeyT  +appuid+ timestamp);
        return "?appkey="+appKeyT+"&timestamp="+timestamp+"&sign="+sign;
    }

    public static List<String> transferJsonToEmailList() throws Exception {
        //目录
        String dirt= "D:\\temp\\火星人酷家乐所有邮箱子账号信息20221110.json";
        File jsonFile = new File(dirt);
        FileReader fr = new FileReader(jsonFile);
        BufferedReader br = new BufferedReader(fr);
        String line;
        StringBuilder jsonStrBuilder =new StringBuilder();
        while((line = br.readLine()) != null){
            jsonStrBuilder.append(line);
        }
        br.close();
        fr.close();
        String jsonStr = jsonStrBuilder.toString();
        JSONObject jsonR = JSONObject.parseObject(jsonStr);
        JSONArray accountArray = jsonR.getJSONObject("d").getJSONArray("result");
        List<String> emailList = new ArrayList();
        for (int i=accountArray.size()-1;i>=0;i--){
            String email = accountArray.getJSONObject(i).getJSONObject("account").getString("email");
            String appUid = accountArray.getJSONObject(i).getJSONObject("account").getString("appUid");
            if (appUid!=null){
                emailList.add(email);
            }

        }
        return emailList;
    }

    public static String md5(String str) {

        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (java.security.NoSuchAlgorithmException ex) {
            //断言失败：JDK 带有 MD5 算法实现
            throw new AssertionError(ex);
        }
        byte[] res = md.digest(str.getBytes());
        return dumpBytes(res);
    }
    private static String dumpBytes(byte[] bytes) {
        int size = bytes.length;
        StringBuffer sb = new StringBuffer(size * 2);
        String s;
        for (int i = 0; i < size; ++i) {
            s = Integer.toHexString(bytes[i]);
            if (s.length() == 8) {          // -128 <= bytes[i] < 0
                sb.append(s.substring(6));
            } else if (s.length() == 2) {   // 16 <= bytes[i] < 128
                sb.append(s);
            } else {
                sb.append("0" + s);         // 0 <= bytes[i] < 16
            }
        }
        return sb.toString();
    }
    public static String arrayToSqlStr(List<String> emailList) {
        List<String> newList = new ArrayList<String>();
        for (String s : emailList) {
            StringBuilder item = new StringBuilder();
            item.append("'").append(s).append("'");
            newList.add(item.toString());
        }
        String sqlStr = newList.toString().substring(1, newList.size()+1);
        return newList.toString();
    }
}
